from pathlib import Path
import random
import shutil

def getDirList():# 可以把目录传进来
    """获取各级目录的列表，并创建目录"""
    dir_lst = []
    p1 = Path('a/b/c/d')
    p1.mkdir(parents=True, exist_ok=True)
    px = p1.parent
    dir_lst.append(str(p1))
    dir_lst.append(str(px))
    while str(px) != str(px.parent):
        px = px.parent
        dir_lst.append(px)
    return dir_lst[0:-1]

def getFileName():# 文件数量也可以作为参数传递
    """获取随机生成的50个文件名"""
    name_coll = set()
    word_lst = [chr(i) for i in range(97, 123)]
    while len(name_coll) < 50:
        word_choices = random.choices(word_lst, k = 4)
        name_coll.add("".join(word_choices))
    return list(name_coll)

def touch_file():
    """将目录和文件名组合，并最终创建该文件"""
    dirName = getDirList()
    fileName = getFileName()
    for f in fileName:
        file = "{}/{}".format(random.choice(dirName), f)
        Path(file).touch(exist_ok=True)
        
touch_file()

def fn(current_dir, names):
    """忽略需要拷贝的文件"""
    return {name for name in names if ((not name.startswith("x") and not name.startswith("y") and not name.startswith("z")) and not (Path(current_dir, name)).is_dir())}

shutil.copytree('a', 't', ignore=fn)